package com.zjm.servlet.servlet07_forward;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ZJM
 * @date 2024/4/14 17:25
 * 请求转发
 */
public class RequestForward01Servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Servlet1处理");
        req.setAttribute("key", "Servlet1");
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/forward2");
        //请求转发
        requestDispatcher.forward(req, resp);
        // req.getRequestDispatcher("/forward2").forward(req, resp);

    }
}
